package cn.jilian.admin.web;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import cn.jilian.entity.Menu;
import cn.jilian.security.util.ShiroUtils;
import cn.jilian.sys.service.MenuService;

@Controller
public class MainController {

	@Value("${app.dock.name}")
	private String appName;
	@Value("${app.login.url}")
	private String loginViewUrl;
	@Value("${app.menu.module}")
	private Integer menuModuleId;
	
	@Autowired
	private MenuService menuService;
	
	public static final String USER_INFO="userInfo";
	
	@GetMapping("/")
	public String index(HttpSession session,Model model) {
		if(session.getAttribute(USER_INFO)==null) {
			return "redirect:"+loginViewUrl;
		}
		model.addAttribute("appName", appName);
		List<Menu> ms=menuService.loadUserMenu(ShiroUtils.getUser(),menuModuleId);
		model.addAttribute("menuTree", ms);
		return "index";
	}
	
	@GetMapping("/index.html")
	public String main(HttpSession session,Model model) {
		return index(session,model);
	}

	
}
